package com.sinosoft.brokerchannel.base.utile;

import java.io.ByteArrayInputStream;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPMessage;

import com.sinosoft.brokerchannel.base.common.ChannelConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 功能：SoapUtils工具类
 * @author shilk
 * @date 2017-9-27 20:28:28
 */
public class SoapUtils {
	 private final static Logger logger = LoggerFactory.getLogger(SoapUtils.class);
	
	  private SoapUtils() {
	  }

	/**
	 * 	 
	 *  throws BusinessException
	 * 需求名称：[非车理赔渠道平台]
	 *  功能:[把soap字符串格式化为SOAPMessage]
	 *  @author [shilk]
	 *  @date 2017年9月27日 下午8:27:11
	 *  功能说明：
	 *	   1.入参：指定soap格式XML报文；<br/>
	 *	   2.反参：SOAPMessage对象。<br/>
	 */
    public static SOAPMessage formatSoapString(String soapString) throws BusinessException {
        MessageFactory msgFactory;
        try {
            msgFactory = MessageFactory.newInstance();
            SOAPMessage reqMsg = msgFactory.createMessage(new MimeHeaders(),new ByteArrayInputStream(soapString.getBytes("UTF-8")));
            reqMsg.saveChanges();
            return reqMsg;
        } catch (Exception e) {
        	logger.error("formatSoapString exception",e);
            throw new BusinessException(ChannelConstants.ExceptionResult.SOAPTOSOAPMESSAGE.getCode(),
					ChannelConstants.ExceptionResult.SOAPTOSOAPMESSAGE.getMessage()+e.getMessage(),
					null);
        }
    }
}
